package com.sttk.secreconeclick.bookkeep;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.sttk.secreconeclick.bookkeep.bean.AccountBookBean;
import com.sttk.secreconeclick.bookkeep.bean.BillTypeBean;
import com.sttk.secreconeclick.bookkeep.databinding.ActivityHomeBinding;
import com.sttk.secreconeclick.bookkeep.fragment.BookKeepFragment;
import com.sttk.secreconeclick.bookkeep.fragment.HomeFragment;
import com.sttk.secreconeclick.bookkeep.fragment.MyFragment;
import com.sttk.secreconeclick.bookkeep.fragment.SaveMoneyFragment;
import com.sttk.secreconeclick.bookkeep.fragment.StatisticsFragment;
import com.sttk.secreconeclick.bookkeep.utils.AppSpUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> {

    @Override
    protected void initView() {
        super.initView();
        List<AccountBookBean> list = AppSpUtils.getAccountBookList();
        if (list == null) {
            list = new ArrayList<>();
            List<BillTypeBean> listExpenditure = new ArrayList<>();
            listExpenditure.add(new BillTypeBean(R.drawable.gongzi2, R.drawable.gongzi4, R.drawable.gongzi3, "工资"));
            listExpenditure.add(new BillTypeBean(R.drawable.canyin2, R.drawable.canyin4, R.drawable.canyin3, "餐饮"));
            listExpenditure.add(new BillTypeBean(R.drawable.shuiguo2, R.drawable.shuiguo4, R.drawable.shuiguo3, "水果"));
            listExpenditure.add(new BillTypeBean(R.drawable.maicai2, R.drawable.maicai4, R.drawable.maicai3, "买菜"));
            listExpenditure.add(new BillTypeBean(R.drawable.haizi2, R.drawable.haizi4, R.drawable.haizi3, "孩子"));
            listExpenditure.add(new BillTypeBean(R.drawable.lvxing2, R.drawable.lvxing4, R.drawable.lvxing3, "旅行"));
            listExpenditure.add(new BillTypeBean(R.drawable.riyongpin2, R.drawable.riyongpin4, R.drawable.riyongpin3, "日用品"));
            listExpenditure.add(new BillTypeBean(R.drawable.jiudian2, R.drawable.gongzi4, R.drawable.gongzi3, "酒店"));
            listExpenditure.add(new BillTypeBean(R.drawable.yanjiu2, R.drawable.yanjiu4, R.drawable.yanjiu3, "烟酒"));
            listExpenditure.add(new BillTypeBean(R.drawable.fushi2, R.drawable.fushi4, R.drawable.fushi3, "服饰"));
            listExpenditure.add(new BillTypeBean(R.drawable.yiyao2, R.drawable.yiyao4, R.drawable.yiyao3, "医药"));
            listExpenditure.add(new BillTypeBean(R.drawable.baoxian2, R.drawable.baoxian4, R.drawable.baoxian3, "保险"));
            listExpenditure.add(new BillTypeBean(R.drawable.xuexi2, R.drawable.xuexi4, R.drawable.xuexi3, "学习"));
            listExpenditure.add(new BillTypeBean(R.drawable.dianqi2, R.drawable.dianqi4, R.drawable.dianqi3, "电器"));
            listExpenditure.add(new BillTypeBean(R.drawable.shuma2, R.drawable.shuma4, R.drawable.shuma3, "数码"));

            List<BillTypeBean> listIncome = new ArrayList<>();
            listIncome.add(new BillTypeBean(R.drawable.gongzi2, R.drawable.gongzi4, R.drawable.gongzi3, "工资"));
            listIncome.add(new BillTypeBean(R.drawable.touzi2, R.drawable.touzi4, R.drawable.touzi3, "投资"));
            listIncome.add(new BillTypeBean(R.drawable.jiekuan2, R.drawable.jiekuan4, R.drawable.jiekuan3, "借款"));
            listIncome.add(new BillTypeBean(R.drawable.jiangjin2, R.drawable.jiangjin4, R.drawable.jiangjin3, "奖金"));
            listIncome.add(new BillTypeBean(R.drawable.hongbao2, R.drawable.hongbao4, R.drawable.hongbao3, "红包"));
            listIncome.add(new BillTypeBean(R.drawable.tuikuan2, R.drawable.tuikuan4, R.drawable.tuikuan3, "退款"));
            listIncome.add(new BillTypeBean(R.drawable.baoxiao2, R.drawable.baoxiao4, R.drawable.baoxiao3, "报销"));
            list.add(new AccountBookBean(getString(R.string.account_book_type1), 0, getString(R.string.account_book_type1), listExpenditure, listIncome, new ArrayList<>()));
            AppSpUtils.saveAccountBookList(list);
        }
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(StatisticsFragment.class, R.id.llStatistics));
        listFragment.add(new FragmentViewBinder(BookKeepFragment.class, R.id.llBookKeep));
        listFragment.add(new FragmentViewBinder(SaveMoneyFragment.class, R.id.llSaveMoney));
        listFragment.add(new FragmentViewBinder(MyFragment.class, R.id.llMy));
        return listFragment;
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        int id = view.getId();
        if (id == R.id.llHome) {
            mDataBinding.ivHome.setImageResource(R.drawable.index_on);
            mDataBinding.tvHome.setTextColor(Color.parseColor("#323433"));
        } else if (id == R.id.llStatistics) {
            mDataBinding.ivStatistics.setImageResource(R.drawable.tongji_on);
            mDataBinding.tvStatistics.setTextColor(Color.parseColor("#323433"));
        } else if (id == R.id.llBookKeep) {
            mDataBinding.ivBookKeep.setImageResource(R.drawable.jizhang_on);
            mDataBinding.tvBookKeep.setTextColor(Color.parseColor("#323433"));
        } else if (id == R.id.llSaveMoney) {
            mDataBinding.ivSaveMoney.setImageResource(R.drawable.cunqian_on);
            mDataBinding.tvSaveMoney.setTextColor(Color.parseColor("#323433"));
        } else if (id == R.id.llMy) {
            mDataBinding.ivMy.setImageResource(R.drawable.wode_on);
            mDataBinding.tvMy.setTextColor(Color.parseColor("#323433"));
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flContainer;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.index_off);
        mDataBinding.tvHome.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivStatistics.setImageResource(R.drawable.tongji_off);
        mDataBinding.tvStatistics.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivBookKeep.setImageResource(R.drawable.jizhang_off);
        mDataBinding.tvBookKeep.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivSaveMoney.setImageResource(R.drawable.cunqian_off);
        mDataBinding.tvSaveMoney.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivMy.setImageResource(R.drawable.wode_off);
        mDataBinding.tvMy.setTextColor(Color.parseColor("#9C9C9C"));
    }

}